package top.byfree.massive.script


import top.byfree.massive.dsl.*
import top.byfree.massive.prh.DBProducer
import top.byfree.massive.orm.RowSet
import top.byfree.massive.prh.FileWriteHandler
import top.byfree.massive.prh.FileProducer
import top.byfree.massive.prh.CatHandler
import top.byfree.massive.prh.Index
import java.sql.DriverManager

data class Demo01Config(
    val url: String = "jdbc:mysql://localhost:3306/account",
    val username: String = "root",
    val password: String = "root",
    val driverClassName: String = "com.mysql.cj.jdbc.Driver",
    val filePath: String = "C:\\Users\\jbyan\\IdeaProjects\\massive\\demo",
    val fileName: String = "jojo.csv"
)

class Classify {
    @field:Index(0)
    lateinit var id: String
    @field:Index(1)
    lateinit var name: String
    @field:Index(2)
    lateinit var gmt_create: String
    override fun toString(): String {
        return "Classify(id='$id', name='$name', gmt_create='$gmt_create')"
    }


}


massive(globalConfig = Demo01Config()) {
//    val t1 = prhUnit(RowSet::class.java) {
//
//        id = "T1"
//        name = "批量导出classify数据"
//
//        producer {
//            val (url, username, password, driverClassName) = it
//            Class.forName(driverClassName)
//            val connection = DriverManager.getConnection(url, username, password)
//            DBProducer(connection, "select * from ac_classify")
//        }
//
//        handler {
//            FileWriteHandler(
//                it.filePath,
//                it.fileName,
//                ",",
//                post = "\n",
//                order = mutableListOf("id", "name", "gmt_create"),
//            )
//        }
//
//    }

    val t2 = prhUnit(Classify::class.java) {
        id = "T2"
        name = "批量导入classify数据"

        producer {
            FileProducer(
                Classify::class.java,
                it.filePath,
                it.fileName,
                ",",
            )
        }

        handler {
            CatHandler(Classify::class.java)
        }

    }

    route(START, success = t2)
    route(t2, success = END, fail = END)
}





